{	Problem: http://codeforces.ru/problemset/problem/56/C
	Verdict: Accepted

}
var s,t:string; i,res,count,j,p,k,kol:integer; st:array[1..1001] of integer; was:array[1..1001] of boolean; n:array[1..1001] of string; sv:array[1..1001,1..1001] of byte;
procedure dfs(v:integer);
var j:integer;
begin
was[v]:=true;
for j:=1 to count do
  if (sv[v,j]<>0) and (was[j]=false) then dfs(j);
end;
begin
for k:=1 to 1001 do fillchar(sv[k],sizeof(sv[k]),0);
readln(s);
count:=0;
res:=0;
t:='';
p:=1;
kol:=0;
for i:=1 to length(s) do begin
  if (s[i]=':') then begin
    inc(count);
    n[count]:=t;
    t:='';
    inc(kol);
    st[kol]:=count;
  end else
  if (s[i]='.') or (s[i]=',') then begin
    if t<>'' then begin
      inc(count);
      n[count]:=t;
      t:='';
      inc(kol);
      st[kol]:=count;
    end;
    if s[i]='.' then begin
      for k:=1 to kol-1 do sv[st[k],st[kol]]:=1;
      st[kol]:=0;
      dec(kol);
    end;
  end else t:=t+s[i];
end;
for i:=1 to count-1 do begin
  for j:=i+1 to count do if (n[i]=n[j])then begin
    if sv[i,j]=1 then inc(res);
  end;
end;
writeln(res);
readln;
end.